<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="网关MAC地址" prop="gw_mac">
        <el-input
          v-model="queryParams.gw_mac"
          placeholder="请输入网关MAC地址"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手环MAC地址" prop="wb_mac">
        <el-input
          v-model="queryParams.wb_mac"
          placeholder="请输入手环MAC地址"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="action">
        <el-select
          v-model="queryParams.action"
          placeholder="请选择任务状态"
          style="width: 200px"
          clearable
        >
          <el-option
            v-for="dict in action_ota"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="类型" prop="type">
        <el-select
          v-model="queryParams.type"
          default-first-option
          placeholder="请选择固件类型"
          style="width: 260px"
        >
          <el-option
            v-for="dict in firmware_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
        <!-- <el-input
          v-model="queryParams.type"
          placeholder="请输入固件类型"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        /> -->
      </el-form-item>
      <!-- <el-form-item label="固件名称" prop="firmwareid">
        <el-select v-model="queryParams.firmwareid" placeholder="请选择固件" style="width: 200px">
          <el-option
            v-for="dict in firmwaresLists"
            :key="dict.id"
            :label="dict.name"
            :value="dict.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="固件类型" prop="firmware">
        <el-select v-model="queryParams.firmware" placeholder="请选择固件类型" style="width: 200px">
          <el-option
            v-for="dict in firmware_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="创建时间" style="width: 308px">
            <el-date-picker
               v-model="dateRange"
               value-format="YYYY-MM-DD"
               type="daterange"
               range-separator="-"
               start-placeholder="开始日期"
               end-placeholder="结束日期"
            ></el-date-picker>
         </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        <el-button icon="Refresh" @click="getGUList">网关升级统计</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['system:post:add']"
          >新增OTA任务</el-button
        >
      </el-col> -->
      <!--<el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="creatOTA"
          v-hasPermi="['system:post:add']"
          >创建OTA任务</el-button
        >
      </el-col>-->
      <!-- <el-col :span="1.5">
            <el-button
               type="success"
               plain
               icon="Edit"
               :disabled="single"
               @click="handleUpdate"
               v-hasPermi="['system:post:edit']"
            >修改</el-button>
         </el-col>
         <el-col :span="1.5">
            <el-button
               type="danger"
               plain
               icon="Delete"
               :disabled="multiple"
               @click="handleDelete"
               v-hasPermi="['system:post:remove']"
            >删除</el-button>
         </el-col>
         <el-col :span="1.5">
            <el-button
               type="warning"
               plain
               icon="Download"
               @click="handleExport"
               v-hasPermi="['system:post:export']"
            >导出</el-button>
         </el-col> -->
      <right-toolbar
        :showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="postList"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column
        label="序号"
        width="60"
        align="center"
        fixed="left"
        prop="index"
      >
        <template #default="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>

      <!-- <el-table-column label="任务号" align="center" prop="id" fixed="left"/> -->
      <!-- <el-table-column label="固件类型" align="center" prop="firmware">
        <template #default="scope">
          <dict-tag :options="firmware_type" :value="scope.row.firmware" />
        </template>
      </el-table-column> -->
      <el-table-column
        label="任务编号"
        min-width="300"
        align="center"
        fixed="left"
        prop="taskid"
        sortable
      />
      <el-table-column
        label="网关MAC"
        min-width="150"
        fixed="left"
        align="center"
        prop="gw_mac"
        sortable
      >
        <template #default="scope">
          <!-- 根据网关MAC生成不同的颜色 -->
          <el-tag :style="{ backgroundColor: getGatewayTagColor(scope.row.gw_mac) }">
            {{ scope.row.gw_mac }}
          </el-tag>
        </template>
      </el-table-column>
      <!-- <el-table-column label="网关是否全部" align="center" prop="gw_full" /> -->
      <el-table-column
        label="手环MAC"
        min-width="150"
        align="center"
        prop="wb_mac"
      />
      <!-- <el-table-column label="手环是否全部" align="center" prop="wb_full" /> -->
      <el-table-column label="状态" align="center" prop="action">
        <template #default="scope">
          <dict-tag :options="action_ota" :value="scope.row.action" />
        </template>
      </el-table-column>
      <el-table-column
        label="更新时间"
        align="center"
        prop="time"
        min-width="260"
        sortable
      >
        <template #default="scope">
          <!-- {{ scope.row.time ? formartIOSDate(scope.row.time) : "--" }} -->
          <span v-if="scope.row.time">
            {{scope.row.time || '--'}}( <span style="color: #67c23a;">{{ formatOnlineTime(scope.row.time) }}</span> )
          </span>
          <span v-else> -- </span>
        </template>
      </el-table-column>
      <el-table-column label="进度" align="center" prop="value" width="180">
        <template #default="scope">
          <el-progress
            :text-inside="true"
            :stroke-width="15"
            :percentage="scope.row.value == null ? 0 : Number(scope.row.value)"
            :status="
              scope.row.action == 'error'
                ? 'exception'
                : scope.row.action == 'success'
                ? 'success'
                : ''
            "
          ></el-progress>
        </template>
      </el-table-column>
      <el-table-column
        label="类型"
        width="100"
        align="center"
        prop="type"
      >
        <template #default="scope">
          <dict-tag v-if="scope.row?.type" :options="firmware_type" :value="[scope.row?.type]" />
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        fixed="right"
        width="90"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
            link
            type="primary"
            icon="View"
            @click="handleView(scope.row)"
            >详细</el-button
          >
          <!-- <el-button
            link
            type="primary"
            icon="Edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:post:edit']"
            >修改</el-button
          >
          <el-button
            link
            type="primary"
            icon="Delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:post:remove']"
            >删除</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 详情 -->
    <el-dialog :title="title" v-model="open" width="90%" append-to-body>
      <el-row :gutter="20">
        <el-col :span="5" :xs="24">
          <el-card class="box-card">
            <template v-slot:header>
              <div class="clearfix">
                <span>手环信息</span>
              </div>
            </template>
            <div class="list-group-top-none">
              <ul class="list-group list-group-striped">
                <li class="list-group-item">
                  <!-- <svg-icon icon-class="cpu" /> -->
                  <el-icon class="cpu"><plus /></el-icon>MAC地址
                  <div class="pull-right">
                    {{ queryParamsDetail.current_wb.wb_mac || "--" }}
                  </div>
                </li>
                <li class="list-group-item">
                  <svg-icon icon-class="phone" />版本号
                  <div class="pull-right">
                    {{ queryParamsDetail.current_wb.fw_version || "--" }}
                  </div>
                </li>
              </ul>
            </div>
          </el-card>
        </el-col>
        <el-col :span="19" :xs="24">
          <el-card class="wristbandDetail">
            <template v-slot:header>
              <div class="clearfix">
                <span>最近数据</span>
                <!-- 共查找到<b style="color:#F56C6C">{{ totalDetail || 0 }}</b>条 -->
              </div>
            </template>
            <!-- <el-form
                  :model="queryParamsDetail"
                  ref="queryDetailRef"
                  :inline="true"
                >
                  <el-form-item label="网MAC地址" prop="gw_mac">
                    <el-input
                      v-model="queryParamsDetail.gw_mac"
                      placeholder="请输入网关MAC地址"
                      clearable
                      style="width: 200px"
                      @keyup.enter="handleQueryDetail"
                    />
                  </el-form-item>
                  <el-form-item label="创建时间">
                    <el-date-picker
                      v-model="queryParamsDetail.date"
                      type="datetimerange"
                      range-separator="至"
                      value-format="YYYY-MM-DD HH:mm:ss"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期">
                    </el-date-picker>
                  </el-form-item>
                  <el-form-item>
                  <el-button type="primary" icon="Search" @click="handleQueryDetail">搜索</el-button>
                    <el-button icon="Refresh" @click="resetQueryDetail">重置</el-button>
                  </el-form-item>
                </el-form> -->
            <el-table
              v-loading="loadingDetail"
              :data="wristbandDetail"
              size="small"
            >
              <el-table-column label="日志编号" align="center" prop="id" width="100" sortable/>
              <el-table-column label="任务编号" align="center" prop="taskid" />
              <el-table-column label="网关MAC" align="center" prop="gw_mac"  min-width="140" sortable/>
              <el-table-column v-if="queryParamsDetail.type == 'web-app'" label="手环MAC" align="center" prop="wb_mac"  min-width="140" sortable/>
              <el-table-column label="固件类型" align="center" prop="type"  width="140"/>
              <el-table-column
                label="进度"
                align="center"
                prop="value"
                width="100"
              >
                <template #default="scope">
                  <el-progress
                    :text-inside="true"
                    :stroke-width="15"
                    :percentage="
                      scope.row.value == null ? 0 : Number(scope.row.value)
                    "
                    :status="
                      scope.row.action == 'error'
                        ? 'exception'
                        : scope.row.action == 'success'
                        ? 'success'
                        : ''
                    "
                  ></el-progress>
                </template>
              </el-table-column>
              <el-table-column label="状态" align="center" prop="action" width="80">
                <template #default="scope">
                  <dict-tag :options="action_ota" :value="scope.row.action" />
                </template>
              </el-table-column>
              <el-table-column
                label="创建时间"
                align="center"
                prop="time"
                width="150"
                sortable
              />
              
            </el-table>
            <pagination
              v-show="totalDetail > 0"
              :layout="'total, sizes, prev, pager, next'"
              :total="totalDetail"
              :small="true"
              v-model:page="queryParamsDetail.pageNum"
              v-model:limit="queryParamsDetail.pageSize"
              @pagination="getWristbandDetails"
              style="max-width: 100%; margin: 0 auto"
            />
          </el-card>
        </el-col>
      </el-row>
      <template #footer>
        <div class="dialog-footer">
          <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
          <el-button @click="cancelDetail">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 添加或修改岗位对话框 -->
    <!-- <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form
        ref="firmwareRef"
        :model="form"
        :rules="rules"
        label-width="100px"
        @submit.prevent
      >
      <el-form-item label="是否全选">
          <el-radio-group v-model="form.full" prop="full">
            <el-radio value="0">是</el-radio>
            <el-radio value="1">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="固件类型" prop="firmware">
          <el-select
            v-model="form.firmware"
            multiple
            allow-create
            filterable
            placeholder="请选择固件类型"
          >
            <el-option
              v-for="dict in firmware_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="固件名称" prop="name">
          <el-select
            v-model="form.firmwareid"
            multiple
            placeholder="请选择固件名称"
          >
            <el-option
              v-for="post in postList"
              :key="post.id"
              :label="post.name"
              :value="post.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="网关" prop="gw_mac">
          <el-input v-model="form.gw_mac" placeholder="请输入网关" />
        </el-form-item>
        <el-form-item label="手环网关" prop="wb_mac">
          <el-input v-model="form.wb_mac" placeholder="请输入手环网关" />
        </el-form-item>
        <el-form-item label="状态" prop="action">
          <el-radio-group v-model="form.action" prop="action">
            <el-radio
              v-for="action in action_ota"
              :key="action.value"
              :value="action.value"
              >{{ action.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="value">
          <el-input v-model="form.value" placeholder="备注" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog> -->

    <!-- OTA任务创建 -->
    <!-- <el-dialog :title="title" v-model="openOTA" width="500px" append-to-body>
      <el-form
        ref="OTARef"
        :model="formOTA"
        :rules="rulesOTA"
        label-width="100px"
        @submit.prevent
      >
        
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitFormOTA">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog> -->
    <!-- 在现有模板中添加对话框 -->
    <el-dialog title="网关升级统计" v-model="guDialogVisible" width="70%">
      <el-table :data="guTableData" style="width: 100%">
        <el-table-column prop="gw_mac" label="网关MAC(手环成功升级数)">
          <template #default="scope">
            {{ scope.row.gw_mac }} ({{ scope.row.deviceCount }})
          </template>
        </el-table-column>
        <el-table-column prop="latestTaskId" label="最新任务ID" show-overflow-tooltip/>
        <el-table-column prop="devices" label="手环列表">
          <template #default="{ row }">
            {{ row.devices.join(', ') }}
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script setup name="Post">
import { onUnmounted } from 'vue';
import { getType } from "@/api/system/dict/type";
import {
  getOtaTaskById,
  getOtaActionLogList,
  otaLogDetail,
  getGatewayUpgradeStats,
} from "@/api/system/firmware/ota";
import { formatDate, formatSeconds } from "@/utils/dateFormart";

const { proxy } = getCurrentInstance();
const { action_ota, firmware_type } = proxy.useDict(
  "action_ota",
  "firmware_type"
);
console.log("firmware_type>>>>",firmware_type,action_ota);

const postList = ref([]);
const open = ref(false);
const openOTA = ref(false);
const loading = ref(false);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const dateRange = ref([]);
const wristbandDetail = ref([]);
let intervalId = null;
const guDialogVisible = ref(false);
const guTableData = ref([]);
let guTableIntervalId = null; // 新增定时器引用
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 100,
    // firmwareid: undefined,
    // firmware: undefined,
    wb_mac: undefined,
    gw_mac: undefined,
    action: undefined,
    type: 'wb-app',
  },
  rules: {
    version: [
      { required: true, message: "固件版本号不能为空", trigger: "blur" },
    ],
    name: [{ required: true, message: "固件名称不能为空", trigger: "blur" }],
    path: [{ required: true, message: "固件名称不能为空", trigger: "blur" }],
    desc: [{ required: true, message: "固件名称不能为空", trigger: "blur" }],
  },
});
const { queryParams, form, rules } = toRefs(data);

// OTA任务
const dataOTA = reactive({
  formOTA: {},
  queryParamsOTA: {
    pageNum: 1,
    pageSize: 100,
    firmwareid: undefined,
    firmware: undefined,
  },
  rulesOTA: {
    firmware: [
      { required: true, message: "固件类型不能为空", trigger: "blur" },
    ],
    firmwareid: [
      { required: true, message: "固件名称不能为空", trigger: "blur" },
    ],
  },
});

const dataDetail = reactive({
  loadingDetail: false,
  detailType:undefined,
  queryParamsDetail: {
    pageNum: 1,
    pageSize: 15,
    current_wb: undefined,
    wb_mac: undefined,
    gw_mac: undefined,
    id: undefined,
    taskid: undefined,
  },
  totalDetail: 0,
});
const { queryParamsDetail, loadingDetail, detailType, totalDetail } = toRefs(dataDetail);

const { queryParamsOTA, formOTA, rulesOTA } = toRefs(dataOTA);

const options = reactive({
  file: null, // 上传的固件文件
  filename: "firmware", // 默认文件名称
  outputType: "bin", // 默认输出文件类型（例如 .bin 或 .hex）
  previews: {}, // 预览数据（如果需要）
});

// watch(
//   () => firmware_type,
//   (newVal,oldVal) => {
//     console.log('22222222222222222',newVal,oldVal,newVal._object.firmware_type)
//     if (newVal._object.firmware_type.length > 0) {
//       queryParams.value.type = newVal._object.firmware_type[0].value;
//     }
//   },
//   { immediate: true }
// );
// 定义 formatOnlineTime 方法
const formatOnlineTime = (time, status) => {
  if (!time) {
    return ' -- ';
  }
  const countTime = status ? formatSeconds(time) : formatDate(time);
  return countTime || ' -- ';
};
/** 网关升级成功统计 */
function getGUList() {
  // 先清除可能存在的旧定时器
  if (guTableIntervalId) {
    console.log("定时器清除 getGUList");
    clearInterval(guTableIntervalId);
    guTableIntervalId = null;
  }
  getGatewayUpgradeStats().then((response) => {
    console.log("网关升级成功统计----",response?.data);
    guTableData.value = response?.data;
    guDialogVisible.value = true;
    // 设置定时器每4分钟刷新数据（240000毫秒）
    guTableIntervalId = setInterval(() => {
      console.log("定时器执行 网关升级成功统计"); // 调试用，确保定时器每次执行时会打印这个log
      getGatewayUpgradeStats().then((response) => {
        console.log("网关升级成功统计  ----",response?.data);
        guTableData.value = response?.data;
      });
    }, 60000);
    // 定义表格的表头
    // const headers = ['网关MAC', '最新任务ID', '成功升级手环数', '手环列表'];
    // // 准备表格数据
    // const tableData = response.data.map(gateway => [
    //   gateway.gw_mac,
    //   gateway.latestTaskId,
    //   gateway.deviceCount,
    //   gateway.devices.join(', ')
    // ]);
    // // 打印表头
    // console.table([headers, ...tableData]);
  });
}
// 监听对话框关闭事件
watch(guDialogVisible, (newVal) => {
  if (!newVal && guTableIntervalId) {
    console.log("定时器清除 guDialogVisible");
    clearInterval(guTableIntervalId);
    guTableIntervalId = null;
  }
});
/** 查询岗位列表 */
function getList() {
  // loading.value = true;
  getOtaActionLogList(queryParams.value).then((response) => {
    console.log("任务日志----", response.data);
    postList.value = response.data.data;
    //  postList.value = response.rows;
    total.value = response.data.total;
    // loading.value = false;
  });
}

/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}

/** 表单重置 */
function reset() {
  form.value = {
    id: undefined,
    fileid: undefined,
    name: undefined,
    version: undefined,
    raw: false,
    desc: undefined,
    path: undefined,
    firmware: undefined,
  };
  proxy.resetForm("firmwareRef");
}

// OTA表单重置
function resetOTA() {
  formOTA.value = {
    full: false,
    firmware: [], // 固件类型
    gw_mac: "", // 网关
    wb_mac: "", // 手环网关
    action: "start",
    firmwareid: [], // 固件名称
  };
  proxy.resetForm("OTARef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  dateRange.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加固件";
}

// 创建OTA任务
function creatOTA() {
  resetOTA();
  openOTA.value = true;
  title.value = "创建OTA任务";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const id = row.id || ids.value;
  getOtaTaskById(id).then((response) => {
    // console.log(response);
    form.value = response.data;
    open.value = true;
    title.value = "修改OTA任务";
  });
}

/** 查看按钮操作 */
function handleView(row) {
  console.log(row);
  queryParamsDetail.value.date = []; //getCurrentDayDate()
  queryParamsDetail.value.id = row.id;
  queryParamsDetail.value.taskid = row.taskid;
  queryParamsDetail.value.gw_mac = row.gw_mac;
  queryParamsDetail.value.wb_mac = row.wb_mac;
  queryParamsDetail.value.current_wb = row;
  queryParamsDetail.value.type = row.type;
  resetDetail();
  getWristbandDetails();
}

/** 导出按钮操作 */
function handleExport() {
  /*proxy.download("system/post/export", {
    ...queryParams.value
  }, `post_${new Date().getTime()}.xlsx`);*/
}

onMounted(() => {
  // loading.value = true;
  getList();
  intervalId = setInterval(() => {
    // loading.value = true;
    getList();
  }, 5000);
});

onUnmounted(() => {
  if (intervalId) {
    clearInterval(intervalId);
  }
  if (guTableIntervalId) {
    console.log("定时器清除 onUnmounted");
    clearInterval(guTableIntervalId);
  }
});

/** 详情取消按钮 */
function cancelDetail() {
  open.value = false;
  resetDetail();
}

/** 详情表单重置 */
function resetDetail() {
  // proxy.resetForm("wristbandRef");
}

/** 详情搜索按钮操作 */
function handleQueryDetail() {
  queryParamsDetail.value.pageNum = 1;
  getWristbandDetails();
}

/** 详情重置按钮操作 */
function resetQueryDetail() {
  // dateRange.value = [];
  proxy.resetForm("queryDetailRef");
  handleQueryDetail();
}

/** 获取手环详情 */
function getWristbandDetails() {
  // loading.value = true; detailType
  loadingDetail.value = true;
  open.value = true;
  title.value = "手环详情";
  console.log("获取手环详情入参: ", queryParamsDetail.value);
  otaLogDetail(queryParamsDetail.value).then((response) => {
    console.log("获取手环详情", response);
    if (response.code === 200) {
      wristbandDetail.value = response.data.data;
      totalDetail.value = response.data.total;
    } else {
      wristbandDetail.value = [];
      totalDetail.value = 0;
    }
    loadingDetail.value = false;
  });
}

// 定义 getGatewayTagType 函数，根据网关MAC生成不同的标签类型
// const getGatewayTagType = (gwMac) => {
//   // 简单示例：根据MAC地址的最后一位数字来分配不同的标签类型
//   const lastChar = gwMac.slice(-1);
//   const num = parseInt(lastChar, 16); // 将最后一位转换为数字
//   if (num % 3 === 0) {
//     return 'success';
//   } else if (num % 3 === 1) {
//     return 'info';
//   } else {
//     return 'warning';
//   }
// };
// 定义 getGatewayTagColor 函数，根据网关MAC生成不同的颜色
const getGatewayTagColor = (gwMac) => {
  // 简单示例：根据MAC地址的哈希值生成颜色
  let hash = 0;
  for (let i = 0; i < gwMac.length; i++) {
    hash = gwMac.charCodeAt(i) + ((hash << 5) - hash);
  }
  const hue = hash % 360; // 色相值范围 0 - 359
  return `hsl(${hue}, 70%, 80%)`;
};
</script>
<style lang="scss" scoped>
.list-group-top-none .list-group-striped > .list-group-item {
  border-top: none;
}
.wristbandDetail {
  :deep(.pagination-container .el-pagination) {
    right: 20px;
  }
}
</style>
